//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    userInfo: {},
    user_id:'',
    plate:[]
  },
  //事件处理函数
  onLoad:function(){
    wx.startPullDownRefresh();
  },
  onShow: function () {
    var value = wx.getStorageSync('user_id'); 
    if(value){
      this.getPlateList();
    }else{
      app.login()
      .then(app.doLogin)
      .then(app.checkAuth('scope.userInfo'))
      .then(app.getUserInfo)
      .then(this.getPlateList)
      .then(app.setUserData).catch(app.toLoad)
    }

  },
  getPlateList: function () {
    let that = this;
    return new Promise((resolve,reject)=>{
      wx.request({
        url: 'https://rtutrip.aihuodong.top/index/index/get_plate_list',
        data: {},
        success(res) {
          console.log(res.data.data);
          that.setData({
            plate: res.data.data.plate
          })
          resolve(res);
          wx.stopPullDownRefresh();
        }
      })
    })
  },
  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  onShareAppMessage: function (e) {
    return {
      title: '塞浦路斯土耳其免费信息平台',
      path: '/pages/plate/plate'
    }
  }
})
